/**
 * @Author: LongTao
 * @program: day04_longtao_springmvc_1917JA_20210108
 * @description:
 * @create: 2021-01-19 16:53
 * @version:1.0
 **/
package com.springmvc.longtao.smbms.utils;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StringToDate implements Converter<String, Date> {
    private String pattern;

    public StringToDate(String pattern) {
        this.pattern = pattern;
    }

    @Override
    public Date convert(String source) {
        System.out.println("pattern = " + pattern);
        System.out.println("source = " + source);
        Date date=null;
        try {
            date= new SimpleDateFormat(pattern).parse(source);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}